import { TOKEN_KEY, USER_KEY } from '@/utils/config.js'

export const  setToken = (token) => {
  uni.setStorageSync(TOKEN_KEY, token)
}
export const  getToken = () => {
  return uni.getStorageSync(TOKEN_KEY)
}

export const  removeToken = () => {
  uni.removeStorageSync(TOKEN_KEY)
}


export const  setUser = (user) => {
  uni.setStorageSync(USER_KEY, user)
}
export const  getUser = () => {
  return uni.getStorageSync(USER_KEY)
}

export const  removeUser = () => {
  uni.removeStorageSync(USER_KEY)
}
export function smartGoBack(defaultUrl = '/pages/dashboard/index', options = {}) {
  // const pages = getCurrentPages()
  // const isH5 = typeof window !== 'undefined'
  // const { forceReplace = false } = options

  // if (forceReplace) {
  //   // 强制跳转，不压入历史
  //   uni.reLaunch({ url: defaultUrl })
  // } else if (pages.length > 1) {
  //   uni.navigateBack()
  // } else if (isH5 && window.history.length > 1) {
  //   window.history.back()
  // } else {
  //   uni.reLaunch({ url: defaultUrl })
  // }
  const isH5 = typeof window !== 'undefined'
  if(isH5){
    if(window.location.pathname === '/pages/dashboard/index'){
    return false
    }else{
      uni.navigateBack()
    }
  }else{
    return uni.navigateBack()
  }
}
